 <%@ page import="java.util.function.Function" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: 32104
  Date: 2024/6/6
  Time: 下午1:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>校验</title>
    <link href="../../CSS/Second.css" type="text/css" rel="stylesheet">
</head>
<body>
<%
    request.setCharacterEncoding("utf-8");
    String name = request.getParameter("name");
    String password = request.getParameter("password");

    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;

    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/student?serverTimezone=Asia/Shanghai";
        String userName = "root";
        String userPassword = "root";
        connection = DriverManager.getConnection(url, userName, userPassword);
        String sql = "select * from admin where name=? and password=?;";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, name);
        preparedStatement.setString(2, password);
        resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
%>
<script>
    alert("登录成功");
</script>
<p style="background-color: pink;margin: 0px;text-align: center;font-family: 楷体;font-size: 25px;color: aquamarine;">
    请选择你要进行的操作:
    <button style="height: 30px;width: 80px;font-size: 18px;background-color: greenyellow;"><a href="../add/add.jsp" style="text-decoration: none;color: red">新增</a></button>
    <button style="height: 30px;width: 90px;font-size: 18px;background-color: greenyellow;margin: -5px"><a href="../delete/allDelete.jsp" style="text-decoration: none;color: red">全部删除</a></button>
    <button style="height: 30px;width: 80px;font-size: 18px;background-color: greenyellow;margin: -5px"><a href="../Subject/select.jsp" style="text-decoration: none;color: red">查询</a></button>
</p>
<hr style="margin: 5px;border: 7px solid green;">
<div id="d1">
    <table id="table_02" border="1">
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>地址</th>
            <th>电话</th>
            <th>性别</th>
            <th colspan="3">操作</th>
        </tr>
        <%
            try {
                Connection connection1 = DriverManager.getConnection(url, userName, userPassword);
                Statement statement1 = connection1.createStatement();
                String selectSQL = "select * from user_info;";
                ResultSet resultSet1 = statement1.executeQuery(selectSQL);
                while (resultSet1.next()) {
                    int id = resultSet1.getInt("id");
                    String ne = resultSet1.getString("name");
                    int age = resultSet1.getInt("age");
                    String address = resultSet1.getString("address");
                    String phone = resultSet1.getString("phone");
                    int sex = resultSet1.getInt("sex");
                    out.print("<tr>");
                    out.print("<td style='border-left:none' name='ID'>" + id + "</td>");
                    out.print("<td name='name'>" + ne + "</td>");
                    out.print("<td name='age'>" + age + "</td>");
                    out.print("<td name='address'>" + address + "</td>");
                    out.print("<td name='phone'>" + phone + "</td>");
                    if (sex == 0) {
                        out.print("<td>" + "女" + "</td>");
                    } else {
                        out.print("<td>" + "男" + "</td>");
                    }
                    out.print("<td><a href='../select/select01.jsp?id=" + id + "'" + "class='t1'>" + "详情" + "</a></td>");
                    out.print("<td><a href='../update/update.jsp?id=" + id + "'" + " class='t1' >" + "修改" + "</a></td>");
                    out.print("<td><a href='javascript:void(0);' class='t1' onclick='confirmDelete("+id+")'>" + "删除" + "</a></td>");
                    out.print("</tr>");

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        %>
    </table>
    <script type="text/javascript">
        function confirmDelete(id) {
            var y=confirm("你确定要删除这个项目吗？");
            if (y===true) {
                window.location.href = '../delete/delete.jsp?id=' + id;
            } else {
                window.location.href = '../select/select01.jsp'
            }
        }
    </script>
</div>

<%
        } else {
            response.sendRedirect("../../index.jsp");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
%>
</body>
</html>

